package widgets;

import javax.swing.*;
import java.awt.*;

/**
 * This is a much coolear replacement for a JToolbar.
 * @author Neil Dickson
 */
public class CustomToolbar extends JComponent {
	private int		nextX;
	public static final int	PADDING = 8;
	public static final int SPACING = 2;
	public CustomToolbar() {
		setLayout(null);
		nextX = PADDING;
		setSize(nextX,PADDING*2);
	}

	public Insets getInsets() {
		return new Insets(PADDING,PADDING,PADDING,PADDING);
	}

	public Insets getInsets(Insets insets) {
		insets.bottom = PADDING;
		insets.top = PADDING;
		insets.left = PADDING;
		insets.right = PADDING;
		return insets;
	}

	public void addSeparator() {
		nextX += PADDING-SPACING;
		setSize(nextX,getHeight());
	}

	public void addButton(CustomButton button) {
		button.setLocation(nextX,PADDING);
		nextX += button.getWidth()+SPACING;
		add(button);
		setSize(nextX,Math.max(getHeight(),button.getHeight()+PADDING*2));
	}

	public Dimension getPreferredSize() {
		return getSize();
	}

	public Dimension getMaximumSize() {
		return getSize();
	}

	public Dimension getMinimumSize() {
		return getSize();
	}

	protected void paintComponent(Graphics g) {
		g.setColor(Color.WHITE);
		g.fillRect(0,0,getWidth(),getHeight());
		g.setColor(Color.LIGHT_GRAY);
		g.drawLine(0,getHeight()-2,getWidth(),getHeight()-2);
		g.setColor(Color.GRAY);
		g.drawLine(0,getHeight()-1,getWidth(),getHeight()-1);
	}
}